home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / progjrn / pj_7_2.arc / WINDEV1.ARC / SMLTPLNT.C < prev    next >
Text File  |  1988-12-04  |  4KB  |  131 lines

  1. /* 
  2.  * Initialization segment for the Windows small memory model template.
  3.  * This code is discarded after it is used.
  4.  *
  5.  * Written by Bill Hall
  6.  * 3665 Benton Street, #66
  7.  * Santa Clara, CA 95051
  8.  *
  9.  */
  10.  
  11. #include <windows.h>
  12. #include "smltpl.h"
  13.  
  14. /* local function declarations */
  15. static BOOL NEAR RegisterWindowClass(HANDLE);
  16. static void NEAR GetPrevInstanceData(HANDLE);
  17. static BOOL NEAR MakeAndShowMainWnd(HANDLE, HANDLE, int);
  18.  
  19. /* This routine is FAR since it is called from another segment */
  20. BOOL FAR InitProgram(hInstance,hPrevInstance, lpszCmdLine, cmdShow)
  21. HANDLE hInstance, hPrevInstance;
  22. LPSTR lpszCmdLine;
  23. int cmdShow;
  24. {
  25.  
  26.   /* if this is the first instance of the program ... */
  27.     if (!hPrevInstance) {
  28.      /* register the window */
  29.     if (!RegisterWindowClass(hInstance))
  30.         return FALSE;
  31.      /* get the icon string */
  32.     LoadString(hInstance, IDS_ICON,(LPSTR)szIcon,sizeof(szIcon));
  33.     }
  34.  
  35.   /* A previous instance already exists so get global data from there */
  36.     else
  37.     GetPrevInstanceData(hPrevInstance);
  38.  
  39.   /* Create and show the window */
  40.     if (!MakeAndShowMainWnd(hInstance,hPrevInstance, cmdShow))
  41.     return FALSE;
  42.  
  43.     return TRUE;
  44. }
  45.  
  46. /* Every window must belong to a class. We register ours here */
  47. static BOOL NEAR RegisterWindowClass(hInstance)
  48. HANDLE hInstance;
  49. {
  50.  
  51.     PWNDCLASS pWndClass;
  52.     HANDLE hTemp;
  53.  
  54.   /* Load the name string from resources */
  55.     LoadString(hInstance, IDS_APPNAME,(LPSTR)szAppName,sizeof(szAppName));
  56.  
  57.   /* allocate space for the WNDCLASS structure and lock it down */
  58.     hTemp = LocalAlloc(LPTR,sizeof(WNDCLASS));
  59.     pWndClass = (PWNDCLASS)LocalLock(hTemp);
  60.  
  61.   /* fill the structure */    
  62.     pWndClass->hCursor    = LoadCursor(NULL, IDC_ARROW);  /* standard cursor */
  63.     pWndClass->hIcon    = NULL;                /* no icon */
  64.     pWndClass->lpszMenuName = NULL;            /* no class menu */
  65.     pWndClass->lpszClassName = (LPSTR)szAppName;    /* our class name */
  66.     pWndClass->hbrBackground = GetStockObject(WHITE_BRUSH); /*white background*/
  67.     pWndClass->hInstance = hInstance;        /* instance handle */
  68.     pWndClass->style = CS_VREDRAW | CS_HREDRAW; /* standard redraw values */
  69.     pWndClass->lpfnWndProc = MainWndProc;    /* pointer to our window proc */
  70.  
  71.   /* register the class.  if fail, abort */
  72.     if (!RegisterClass((LPWNDCLASS)pWndClass))
  73.     return FALSE;
  74.  
  75.   /* free the memory used */
  76.     LocalUnlock(hTemp);
  77.     LocalFree(hTemp);
  78.  
  79.   /* show success */
  80.     return TRUE;
  81. }
  82.  
  83. /*
  84.    If this not the first instance, we can retrieve static data from a
  85.    previous invocation of the program
  86. */
  87. static void NEAR GetPrevInstanceData(hInstance)
  88. HANDLE hInstance;
  89. {
  90.  
  91.     GetInstanceData(hInstance, (PSTR)szAppName, sizeof(szAppName));
  92.     GetInstanceData(hInstance, (PSTR)szIcon, sizeof(szIcon));
  93.  
  94. }
  95.  
  96. /*
  97.  Create the window, making sure that its position and size are suitable
  98.  for the display.
  99. */
  100. static BOOL NEAR MakeAndShowMainWnd(hInstance, hPrevInstance, cmdShow)
  101. HANDLE hInstance;
  102. HANDLE hPrevInstance;
  103. int cmdShow;
  104. {
  105.  
  106.    char szTitle[50];
  107.  
  108.     LoadString(hInstance, IDS_TITLE,(LPSTR)szTitle,sizeof(szTitle));
  109.  
  110.   /* create the window, letting it fall where Windows wants */
  111.     hWndMain = CreateWindow((LPSTR)szAppName,
  112.                  (LPSTR)szTitle,
  113.                  WS_OVERLAPPEDWINDOW,
  114.                  CW_USEDEFAULT,0,
  115.                  CW_USEDEFAULT,0,
  116.                  (HWND)NULL,
  117.                  (HMENU)NULL,
  118.                  (HANDLE)hInstance,
  119.                  (LPSTR)NULL);
  120.  
  121.   /* if we fail, give up */
  122.     if (hWndMain == NULL)
  123.     return FALSE;
  124.  
  125.   /* finally, display the window and show success */
  126.     ShowWindow(hWndMain, cmdShow);
  127.     UpdateWindow(hWndMain);
  128.  
  129.     return TRUE;
  130. }
  131.